<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="groupForm"  role="form" method="post" action="group/save">
    <input type="hidden" name="orgGroup.node" th:value="${entity.node}" />
    <div class="form-group" >
        <label >父部门名称:</label>
        <input type="text" class="form-control" th:value="${entity.name}" readonly="readonly"  />
    </div>
    <div class="form-group">
        <label for="name">部门名称:</label>
        <input type="text" class="form-control" name="name" id="name"  placeholder="请输入部门名称" />
    </div>
    <div class="form-group" >
        <label for="groupCode">部门编号:</label>
        <input type="text" class="form-control" name="groupCode" id="groupCode"  placeholder="请输入部门编号" />
    </div>
    <div class="form-group" >
        <label for="num">部门编制:</label>
        <input type="text" class="form-control" name="num" id="num"  placeholder="请输入部门编制" />
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $('#groupForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                name: {
                    message: '部门名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '部门名称不能为空'
                        }
                    }
                },
                groupCode: {
                    message: '部门编号验证失败',
                    validators: {
                        notEmpty: {
                            message: '部门编号不能为空'
                        }
                    }
                },
                value: {
                    message: '部门编制验证失败',
                    validators: {
                        notEmpty: {
                            message: '部门编制不能为空'
                        },
                        regexp: {
                            regexp: /^[0-9_]+$/,
                            message: '部门编制必须为数字'
                        },
                        stringLength: {
                            min: 1,
                            max: 18,
                            message: '用部门编制必须在1到18位之间'
                        }

                    }
                }
            }
        })

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk",window.top.document).click(function() {

            var bootstrapValidator = $("#groupForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                var zTree = $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.zTree;
                var selectNode = $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.selectNode;
                $.post($("#groupForm",window.top.document).attr('action'),$("#groupForm",window.top.document).serialize(),function(e){
                    if(e.result){
                        $('.modal-dialog', window.top.document).parent('div').remove()
                        $('body', window.top.document).find('.modal-backdrop').remove();
                        var entity = e.entity;
                        zTree.addNodes(selectNode, {node:entity.node, parentNode:entity.parentNode, name:entity.name,groupId:entity.groupId,groupCode:entity.groupCode });
                        window.Ewin.alert({message:'增加数据成功!'});
                    }else{
                        window.Ewin.alert({message:'增加数据失败!'});
                    }
                })
            }
        });
    })
    ]]>
</script>
</body>
</html>